﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Ini;
using System.Xml.Linq;
using System.Xml;



namespace Sequence
{
    public partial class Results : Form
    {
        public Results()
        {
            InitializeComponent();
        }
        public Results(string sResult, string sFilename)
        {
            InitializeComponent();
            rtbResults.Text = sResult;
            if (sFilename.Length > 0)
            {
                tabPage1.Text =  Path.GetFileNameWithoutExtension(sFilename);
                wbResultsIn.Navigate(sFilename);
            }
            SetPos();
        }

        public Results(string sResult, string sInXml, string sOutXml)
        {
            InitializeComponent();
            rtbResults.Text = sResult;
            
            try
            {
                sInXml = sInXml.Replace("<?xml version=\"1.0\" encoding=\"UTF8\"?>", "");
                
                using (StreamWriter outfile = new StreamWriter("C:\\Sapiens\\Sequence\\temp.xml", false))
                    outfile.Write(sInXml);

                using (StreamWriter outfile2 = new StreamWriter("C:\\Sapiens\\Sequence\\temp2.xml", false))
                    outfile2.Write(sOutXml);

                wbResultsIn.Navigate("C:\\Sapiens\\Sequence\\temp.xml");
                webBrowserOut.Navigate("C:\\Sapiens\\Sequence\\temp2.xml");
            }
            catch
            {
                rtbResults.Text += "Failed to load XML";
            }

            SetPos();
        }

        private void SetPos()
        {
            IniFile ini = new IniFile("C:\\Sapiens\\Sequence\\Sequence.ini");

            this.Left = Convert.ToInt16(ini.IniReadValue("FrmResults", "Left", "100"));
            this.Width = Convert.ToInt16(ini.IniReadValue("FrmResults", "Width", "1200"));
            this.Top = Convert.ToInt16(ini.IniReadValue("FrmResults", "Top", "100"));
            this.Height = Convert.ToInt16(ini.IniReadValue("FrmResults", "Height", "400"));
        }

        private void Results_Load(object sender, EventArgs e)
        {

        }

        private void Results_FormClosing(object sender, FormClosingEventArgs e)
        {
            IniFile ini = new IniFile("C:\\Sapiens\\Sequence\\Sequence.ini");
            ini.IniWriteValue("FrmResults", "Left", this.Left.ToString());
            ini.IniWriteValue("FrmResults", "Width", this.Width.ToString());
            ini.IniWriteValue("FrmResults", "Top", this.Top.ToString());
            ini.IniWriteValue("FrmResults", "Height", this.Height.ToString());
        }

        private void tabControl1_TabIndexChanged(object sender, EventArgs e)
        {
         }

        private void wbResultsIn_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }
    }
}
